package com.ctshk.rpc.order.custom.dto.tourist;

import com.ctshk.common.enums.NumberConstant;
import com.ctshk.rpc.order.custom.dto.order.CustomOrderTouristFeeAdjustDTO;
import com.ctshk.rpc.order.custom.dto.order.CustomOrderTouristOtherFeeDTO;
import com.ctshk.rpc.order.custom.vo.TouristCollectionFeeJson;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 订单收款列表dto
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-25
 */
@Data
@ApiModel(value = "订单收款列表dto", description = "订单收款列表dto")
public class CustomOrderTouristInfoListCollectionDTO implements Serializable {
    @ApiModelProperty(value = "ID")
    private Long id;

    @ApiModelProperty(value = "所属订单")
    private Long orderId;

    @ApiModelProperty(value = "团期ID")
    private Long scheduleId;

    @ApiModelProperty(value = "销售单号")
    private String orderNumber;

    @ApiModelProperty(value = "中文姓")
    private String cnSurname;

    @ApiModelProperty(value = "中文姓名")
    private String cnName;

    @ApiModelProperty(value = "团费")
    private BigDecimal groupFee;

    @ApiModelProperty(value = "代收费用")
    private BigDecimal collectionFee;

    @ApiModelProperty(value = "调整费用")
    private BigDecimal adjustmentCost;

    @ApiModelProperty(value = "其他费用")
    private BigDecimal otherAmount;

    /*@ApiModelProperty(value = "代收费用")
    List<CustomOrderTouristOtherFeeDTO> collectionFeeDTOList;*/

    @ApiModelProperty(value = "代收费用Str")
    private String collectionFeeJson;

    @ApiModelProperty(value = "代收费用")
    private List<TouristCollectionFeeJson> collectionFeeDTOList;

    @ApiModelProperty(value = "调整费用")
    List<CustomOrderTouristFeeAdjustDTO> feeAdjustDTOList;

    @ApiModelProperty(value = "其他金额")
    List<CustomOrderTouristOtherFeeDTO> otherFeeDTOList;

    @ApiModelProperty(value = "付款状态（1 待付款 2 待付余款 3 已付全款 4 已退团）")
    private Integer payStatus;

    @ApiModelProperty(value = "退团状态")
    private Integer quitRefundStatus;

    @ApiModelProperty(value = "应收")
    private BigDecimal totalReceivables;

    @ApiModelProperty(value = "实收")
    private BigDecimal totalPaidIn;

    @ApiModelProperty(value = "未收")
    private BigDecimal remainingReceivables;

    @ApiModelProperty(value = "1：CPM云平台，2 ：CPM代理下单，3 ：PC官网，4 ：安卓，5：IOS，6：H5")
    private Integer orderSource;

    @ApiModelProperty(value = "创建人")
    private Long createId;

    @ApiModelProperty(value = "销售姓名")
    private String saleUserName;

    @ApiModelProperty(value = "销售部门")
    private String saleUserDept;

   /* public void setCollectionFeeDTOList(String collectionFeeDTOList) {
        this.collectionFeeDTOList = new ArrayList<>();
        try {
            String[] lineArray = collectionFeeDTOList.split("\\}\\)");
            for (String line : lineArray) {
                String[] columnArray = line.split("]\\)");
                CustomOrderTouristOtherFeeDTO dto = new CustomOrderTouristOtherFeeDTO();
                if (columnArray.length > 0) {
                    BigDecimal column = new BigDecimal(columnArray[0]);
                    column.setScale(2, BigDecimal.ROUND_HALF_UP);
                    dto.setAmount(column);
                }
                if (columnArray.length > 1) {
                    dto.setFeeName(columnArray[1]);
                }
                this.collectionFeeDTOList.add(dto);
            }
        } catch (Exception e) {
        }
    }*/

    public void setFeeAdjustDTOList(String feeAdjustDTOList) {
        this.feeAdjustDTOList = new ArrayList<>();
        try {
            String[] lineArray = feeAdjustDTOList.split("\\}\\)");
            for (String line : lineArray) {
                String[] columnArray = line.split("]\\)");
                CustomOrderTouristFeeAdjustDTO dto = new CustomOrderTouristFeeAdjustDTO();
                if (columnArray.length > 0) {
                    BigDecimal column = new BigDecimal(columnArray[0]);
                    column.setScale(2, BigDecimal.ROUND_HALF_UP);
                    dto.setAmount(column);
                }
                if (columnArray.length > 1) {
                    dto.setPlusType(Integer.valueOf(columnArray[1]));
                }
                if (columnArray.length > 2) {
                    dto.setName(columnArray[2]);
                }
                this.feeAdjustDTOList.add(dto);
            }
        } catch (Exception e) {
        }
    }

    /*public void setOtherFeeDTOList(String otherFeeDTOList) {
        this.otherFeeDTOList = new ArrayList<>();
        try {
            String[] lineArray = otherFeeDTOList.split("\\}\\)");
            for (String line : lineArray) {
                String[] columnArray = line.split("]\\)");
                CustomOrderTouristOtherFeeDTO dto = new CustomOrderTouristOtherFeeDTO();
                if (columnArray.length > 0) {
                    BigDecimal column = new BigDecimal(columnArray[0]);
                    column.setScale(2, BigDecimal.ROUND_HALF_UP);
                    dto.setAmount(column);
                }
                if (columnArray.length > 1) {
                    dto.setFeeName(columnArray[1]);
                }
                this.otherFeeDTOList.add(dto);
            }
        } catch (Exception e) {
        }
    }*/

    //狀態：取【收款管理】的狀態，退團狀態優先收款狀態
    public Integer getPayStatus() {
        if (Objects.equals(this.quitRefundStatus, NumberConstant.FOUR.getValue())) {
            this.payStatus = NumberConstant.FOUR.getValue();
        }
        return payStatus;
    }
}
